//
//  main.m
//  文件管理
//
//  Created by liuchengming on 16/4/24.
//  Copyright © 2016年 liuchengming. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Student.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool
    {
        NSString * str = @"hello my name is liuchengming!";
        [str writeToFile:@"123.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];   //创建一个文件
        
        Student * a = [[Student alloc]init];
        a.name = @"张三";
        a.age = 20;
        
        Student * b = [[Student alloc]init];
        b.name = @"李四";
        b.age = 21;
        
        Student * c = [[Student alloc]init];
        c.name = @"王五";
        c.age = 23;
        
        NSArray * arr =[NSArray arrayWithObjects:a,b,c, nil];
        
        for (Student * s in arr)
        {
            [s say];
        }
        
        BOOL s = [NSKeyedArchiver archiveRootObject:arr toFile:@"学生.plist"];
        NSLog(@"%d",s);   //写入成功打印1  失败打印0
        
        //读文件
        NSArray * array = [NSKeyedUnarchiver unarchiveObjectWithFile:@"学生.plist"];
        
        //遍历数组   看看是否读文件成功
        for(Student * s in array)
        {
            [s say];
        }
        
        
        
        
    }
    return 0;
}
